package com.ssyt.blog.core.sys.dao;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.ssyt.blog.core.common.BaseDao;
import com.ssyt.blog.core.sys.entity.Discuss;

@Repository
public class DiscussDao extends BaseDao<Discuss, Integer> {

	public List<Discuss> discussListByArticle(int id) {

		return listEntityByHql(
				"SELECT new Discuss(d.id, d.content, d.createTime, u.id, u.name, u.photo) FROM Discuss d,User u WHERE d.userId=u.id AND d.articleId=? order by d.createTime desc",
				id);
	}

	public int addDiscuss(String content, int articleId, int userId) {
		Discuss discuss = new Discuss(null, content, new Date(), articleId,
				userId);
		return save(discuss);
	}

	public void discussInfoDelete(Integer id) {
		Discuss discuss = load(id);
		delete(discuss);
	}

}
